<template>
	<view class="enterprise">

	<u-navbar 
		title="编辑企业信息"
		:border-bottom="false"  
	></u-navbar>
	<view class="enterprise__title">
		企业信息
	</view>
	<view class="enterprise__box">

		<view @click="logoModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				企业logo
			</view>
			<!-- <u-avatar :src="enterpriseData.logo" size="100" style="margin-right: 10px;"></u-avatar>
			 -->
			 <view class="enterprise__box__basicInfo__image">
				<u-image :src="enterpriseData.logoUrl"  width="100%" height="100%" ></u-image>
			 </view>
			<u-modal v-model="logoModal" :show-title="false" :show-confirm-button="false">
				<view class="enterprise__box__basicInfo__modal">
					<view class="enterprise__box__basicInfo__modal__button" @click="previewlogo(enterpriseData.logo)">查看大图</view>
					<view class="enterprise__box__basicInfo__modal__button" @click="chooselogo()">修改图片</view>
				</view>
			</u-modal>
		</view>
		<view @click="codeModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				企业代码
			</view>
			<view class="enterprise__box__basicInfo__value">
				{{enterpriseData.code}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			
			<u-modal v-model="codeModal" title="输入企业代码" :mask-close-able="true">
				<view class="enterprise__box__basicInfo__modal">
					<u-field v-model="enterpriseData.code" :placeholder="enterpriseData.code">
					</u-field>
				</view>
			</u-modal>
		</view>
		<view @click="nameModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				企业名称
			</view>
			<view class="enterprise__box__basicInfo__value">
				{{enterpriseData.name}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			
			<u-modal v-model="nameModal" title="输入企业名称" :mask-close-able="true">
				<view class="enterprise__box__basicInfo__modal">
					<u-field v-model="enterpriseData.name" :placeholder="enterpriseData.name">
					</u-field>
				</view>
			</u-modal>
		</view>
		<view @click="introductionModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				企业简介
			</view>
			<view class="enterprise__box__basicInfo__value">
				{{enterpriseData.briefIntroduction}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			
			<u-modal  v-model="introductionModal" title="输入简介" :mask-close-able="true">
				<view class="enterprise__box__basicInfo__modal">
				<u-field v-model="enterpriseData.briefIntroduction" :placeholder="enterpriseData.briefIntroduction" type="textarea" >
				</u-field>
				</view>
			</u-modal>
		</view>
		<view @click="phontModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				企业联系方式
			</view>
			<view class="enterprise__box__basicInfo__value" >
				{{enterpriseData.phone}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			<u-modal  v-model="phontModal" title="输入企业联系方式" :mask-close-able="true">
				<view class="enterprise__box__basicInfo__modal">
				<u-field v-model="enterpriseData.phone" :placeholder="enterpriseData.phone" type="textarea" >
				</u-field>
				</view>
			</u-modal>
		</view>
		<view @click="editPhoto" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				公司照片
			</view>
			<view class="enterprise__box__basicInfo__value">
				编辑
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
		</view>
		<view @click="addressModal=true" class="enterprise__box__basicInfo">
					<view class="enterprise__box__basicInfo__type">
						地址
					</view>
					<view class="enterprise__box__basicInfo__value">
						{{enterpriseData.address}}
					</view>
					<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
					
					<u-modal v-model="addressModal" title="输入企业地址" :mask-close-able="true">
						<u-field v-model="enterpriseData.address" :placeholder="enterpriseData.address" type="textarea" >
						</u-field>
					</u-modal>
					
				</view>
				
				<view @click="licenseModal=true" class="enterprise__box__basicInfo">
					<view class="enterprise__box__basicInfo__type">
						营业执照
					</view>
		
					 <view class="enterprise__box__basicInfo__image">
						<u-image :src="enterpriseData.businessLinence"  width="100%" height="100%" ></u-image>
					 </view>
					 <u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
					 
					<u-modal v-model="licenseModal" :show-title="false" :show-confirm-button="false">
						<view class="enterprise__box__basicInfo__modal">
							<view class="enterprise__box__basicInfo__modal__button" @click="previewlicense(enterpriseData.businessLinence)">查看大图</view>
							<view class="enterprise__box__basicInfo__modal__button" @click="chooselicense()">修改图片</view>
						</view>
					</u-modal>
				</view>
				
				<view @click="legalModal=true" class="enterprise__box__basicInfo">
					<view class="enterprise__box__basicInfo__type">
						公司法人姓名
					</view>
					<view class="enterprise__box__basicInfo__value">
						{{enterpriseData.legalPersonName}}
					</view>
					<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
					
					<u-modal v-model="legalModal" title="输入法定人姓名" :mask-close-able="true">
						<u-field v-model="enterpriseData.legalPersonName" :placeholder="enterpriseData.legalPersonName" type="textarea" >
						</u-field>
					</u-modal>
				</view>
			
				<view @click="certificateModal=true" class="enterprise__box__basicInfo">
					<view class="enterprise__box__basicInfo__type">
						法人身份证
					</view>
					<!-- <u-avatar :src="enterpriseData.logo" size="100" style="margin-right: 10px;"></u-avatar>
					 -->
					 <view class="enterprise__box__basicInfo__image">
						<u-image :src="enterpriseData.legalPersonCertificateUrl"  width="100%" height="100%" ></u-image>
					 </view>
					<u-modal v-model="certificateModal" :show-title="false" :show-confirm-button="false">
						<view class="enterprise__box__basicInfo__modal">
							<view class="enterprise__box__basicInfo__modal__button" @click="previewCertificate(enterpriseData.legalPersonCertificateUrl)">查看大图</view>
							<view class="enterprise__box__basicInfo__modal__button" @click="chooseCertificate()">修改图片</view>
						</view>
					</u-modal>
				</view>
				
	</view>
	<view class="enterprise__title">
		园区信息
	</view>
	<view class="enterprise__box">

		<view @click="park_idModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				园区ID
			</view>
			<view class="enterprise__box__basicInfo__value">
				{{enterpriseData.parkId}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			
			<u-modal v-model="park_idModal" title="输入园区ID" :mask-close-able="true">
				<u-field v-model="enterpriseData.parkId" :placeholder="enterpriseData.parkId"  >
				</u-field>
			</u-modal>
		</view>
		
		<view @click="room_idModal=true" class="enterprise__box__basicInfo">
			<view class="enterprise__box__basicInfo__type">
				房间ID
			</view>
			<view class="enterprise__box__basicInfo__value">
				{{enterpriseData.rootId}}
			</view>
			<u-icon class="enterprise__box__basicInfo__arrow" color="#b8b8b8" name="arrow-right"></u-icon>
			
			<u-modal v-model="room_idModal" title="输入房间ID" :mask-close-able="true">
				<u-field v-model="enterpriseData.rootId" :placeholder="enterpriseData.rootId"  >
				</u-field>
			</u-modal>
		</view>
		
	</view>
	<view class="bottom-box">
		<view class="bottom-box__cancel" @click="cancelModel=true">取消</view>
		<view class="bottom-box__submit" @click="submit">提交</view>
	</view>
	<u-modal v-model="cancelModel"
		:show-title="false"
		content="确认取消"
		:show-cancel-button="true"
		confirm-color="#177fff"
		@confirm="goback">
	</u-modal>
	<u-modal v-model="submitModel" 
		:show-title="false"
		content="确认提交"
		:show-cancel-button="true"
		confirm-color="#177fff"
		@confirm="submit">
	</u-modal>
	</view>
	
	</view>
</template>

<script>
	// import enterpriseData from "./enterpriseData.js"
	import axios from "axios"
	export default {
		data() {
			return {
				enterpriseData:"",
				codeModal:false,
				nameModal:false,
				introductionModal:false,
				phontModal:false,
				addressModal:false,
				legalModal:false,
				establishDataModal:false,
				business_scopeModal:false,
				identity_numberModal:false,
				park_idModal:false,
				room_idModal:false,
				entry_timeModal:false,
				logoModal:false,
				licenseModal:false,
				certificateModal:false,
				
				logoChange:false,
				licenceChange:false,
				certificateChane:false,
				
				logo:"",
				legalPersonCertificate:"",
				businessLicense:"",
				
				cancelModel:false,
				submitModel:false,
			}
		},
		onLoad(){
			let enterpriseId=this.$Route.query.enterpriseId
			console.log("enterpriseId",enterpriseId)
			this.getEnterprise(enterpriseId)
		},
		methods: {
			getEnterprise(enterpriseId){
				let querydata={
					"enterprise_id":enterpriseId
				}
				this.$Axios({
					method:"get",
					url:this.$store.state.baseURL+"/enterprise/get",
					params:querydata,
				}).then((response)=>{
					if(response.data.state=="Success"){
						this.enterpriseData=response.data.msg;
					}else{
						uni.showToast({
							title:response.data.msg,
							icon:"none",
							duration:2000
						})
					}
				})
			},
			editPhoto(){
				uni.navigateTo({
					url:"/pages/core/mine/enterprise/editPhoto"
				})
			},
			chooselogo(){
				this.logoModal=false
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						console.log('img',res)
						//上传图片
						_this.enterpriseData.logoUrl=res.tempFiles[0].path
						_this.logo=res.tempFiles[0]

					}
				})
			},
			previewlogo(url){
				this.logoModal=false
					uni.previewImage({
						indicator:"number",
						loop:true,
						urls: [url]
					})
				},
			chooselicense(){
				this.licenseModal=false
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						console.log('img',res)
						_this.enterpriseData.businessLicenseUrl=res.tempFiles[0].path
						_this.businessLicense=res.tempFiles[0]
						//上传图片
			
					}
				})
			},
			previewlicense(url){
				this.licenseModal=false
				uni.previewImage({
					indicator:"number",
					loop:true,
					urls: [url]
				})
			},
			
			chooseCertificate(){
				this.certificateModal=false
				let _this=this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera','album'], //从相册选择
					success: function (res) {
						_this.enterpriseData.legalPersonCertificateUrl=res.tempFiles[0].path
						_this.legalPersonCertificate=res.tempFiles[0]
						//上传图片
			
					}
				})
			},
			previewCertificate(url){
				this.certificateModal=false
				uni.previewImage({
					indicator:"number",
					loop:true,
					urls: [url]
				})
			},
			submit(){
				uni.showLoading({
					title:"提交中...",
				})
				let addData=new FormData()
				addData.append("code",this.enterpriseData.code)
				console.log("name","this.name")
				addData.append("name",this.enterpriseData.name)
				addData.append("logo",this.enterpriseData.logo)
				addData.append("briefIntroduction",this.enterpriseData.briefIntroduction)
				addData.append("phone",this.enterpriseData.phone)
				addData.append("type","1")
				addData.append("address",this.enterpriseData.address)
				addData.append("legalPersonName",this.enterpriseData.legalPersonName)
				addData.append("establishmentDate",this.enterpriseData.establishmentDate)
				addData.append("businessLicense",this.enterpriseData.businessLinence)
				addData.append("businessScope",this.enterpriseData.businessScope)
				addData.append("legalPersonCertificate",this.enterpriseData.legalPersonCertificate)
				addData.append("identityNumber",this.enterpriseData.identityNumber)
				addData.append("parkId",this.enterpriseData.parkId)
				addData.append("entryTime",this.enterpriseData.entryTime)
				// addData.append("entryTime",this.enteryTime)
				axios({
					url:this.$store.state.baseURL+"/enterprise/info/modification",
					method:"post",
					headers:{
						// "Content-Type":"multipart/form-data; boundary=----WebKitFormBoundary5NqxviCXpyAjOEV6boundary",
						"Authorization":uni.getStorageSync("token")
					},
					data:addData
				}).then(response=>{
					if(response.data.satus=="Success"){
						uni.showToast({
							title:"修改成功",
							icon:"none",
							duration:2000
						})
					}else{
						uni.showToast({
							title:response.data.msg,
							icon:"none",
							duration:2000
						})
					}
				}).catch((e)=>{
					uni.showToast({
						title:e,
						icon:"none",
						duration:2000,
					})
				})
			
			}
			
			
		}

	}
</script>

<style lang="less">
.enterprise{
	background-color: @uni-bg-color-grey;
}
.enterprise{
	&__title{
		margin-left:@uni-spacing-col-lg;
		margin-top: @uni-spacing-row-sm;
		margin-bottom: @uni-spacing-row-sm;
		font-size: @uni-font-size-sm;
		color: @font-color-grey;
	}
	&__box{
		margin-top: @uni-spacing-row-sm;
		background-color: #fff;
		&__pic{
			margin: 10rpx 30rpx;
		}
		&__basicInfo{
			padding: @uni-spacing-row-lg 0;
			margin:0 @uni-spacing-col-lg ;
			display: flex;
			justify-content: flex-end;
			align-items: center;
			border-bottom: 0.1px solid #dde3f1;
			
			&__modal{
				display: flex;
				flex-direction: column;
				&__button{
					margin:15rpx auto;
					text-align: center;
					padding: 10rpx 90rpx;
				}
				&__button :hover{
					background-color: #f4f4f4;
						
				}
				&__item{
					margin:0px auto 10px 30px;
				}
			}
			&__type{
				margin-right: auto;
			}
			&__image{
				width: 50rpx;
				height: 50rpx;
			}
			&__value{
				color: #9f99a5;
			}
			&__arrow{
			}
		}
	}
}
.bottom-box{
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	position: fixed;
	padding: @uni-spacing-row-lg @uni-spacing-col-lg;
	bottom: 0;
	width: calc(100vw);
	background-color: #fff;
	
	&__cancel{
		margin-right: @uni-spacing-col-lg;
		padding-top: @uni-spacing-row-base;
		padding-bottom: @uni-spacing-row-base;
		text-align: center;
		flex: 0.5;
		border-radius: @uni-border-radius-base;
		border: 1px solid @font-color-blue;
		font-size: @uni-font-size-lg;
		color: @font-color-blue;
	}
	&__submit{
		padding-top: @uni-spacing-row-base;
		padding-bottom: @uni-spacing-row-base;
		text-align: center;
		flex: 1;
		border-radius: @uni-border-radius-base;
		border: 1px solid @font-color-blue;
		background-color: @uni-bg-color-blue;
		font-size: @uni-font-size-lg;
		color: #fff;
	}
}
</style>
